package com.funcourse.demo.aliyun.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Data
@Component
public class OssConfig {

  @Value("${aliyun.oss.domain.pic:https://huixi-pic-hub.oss-cn-beijing.aliyuncs.com}")
  private String picDomain;

  //	String endpoint = "http://oss-cn-qingdao.aliyuncs.com";
  @Value("${aliyun.oss.api.endpoint:http://oss-cn-beijing.aliyuncs.com}")
  private String endpoint;

  //	String accessKeyId = "uNvXsccxMOOKueUi";
  @Value("${aliyun.oss.access.key.id:LTAI4G6WM1tif1wZuxCjj2L2}")
  private String accessKeyId;

  //	String accessKeySecret = "A8oJ32XtkbEax5VlltWLM0MWsRRbdE";
  @Value("${aliyun.oss.access.key.secret:8V3lImSY8q0UCLmwPhMB4tbyC3hVk3}")
  private String accessKeySecret;

  //	String bucketName = "renyanda";
  @Value("${aliyun.oss.bucketname.weletcode:huixi-user-upload}")
  private String bucketName;

  private OSS ossClient;

  @PostConstruct
  public void buildOssClient(){
    ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
  }

  @PreDestroy
  public void destroy(){
    ossClient.shutdown();
  }

}
